<!DOCTYPE html>
<html lang="zh-cn">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">
  <link rel="icon" type="image/png" sizes="16x16" href="https://gitee.com/reku1997/reku1997/raw/master/reku.ico">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"reku1997.gitee.io","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":true,"style":"flat"},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"appID":"AW5K8S9IEE","apiKey":"d7e666d597854738d2fb31ecaa989aa5","indexName":"dev_reku1997","hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="我们都知道后缀自动机的构造是比较难以理解的，所以我想先知道后缀自动机构建出来的东西是什么。">
<meta property="og:type" content="article">
<meta property="og:title" content="后缀自动机">
<meta property="og:url" content="https://reku1997.gitee.io/2017/09/28/%E5%90%8E%E7%BC%80%E8%87%AA%E5%8A%A8%E6%9C%BA/index.html">
<meta property="og:site_name" content="Reku">
<meta property="og:description" content="我们都知道后缀自动机的构造是比较难以理解的，所以我想先知道后缀自动机构建出来的东西是什么。">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2017-09-28T14:27:51.000Z">
<meta property="article:modified_time" content="2021-12-16T12:15:01.000Z">
<meta property="article:author" content="Reku">
<meta property="article:tag" content="后缀自动机">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://reku1997.gitee.io/2017/09/28/%E5%90%8E%E7%BC%80%E8%87%AA%E5%8A%A8%E6%9C%BA/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-cn'
  };
</script>

  <title>后缀自动机 | Reku</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/atom.xml" title="Reku" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="Toggle navigation bar">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">Reku</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>Home</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-fw fa-user"></i>About</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>Tags</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>Archives</a>

  </li>
        <li class="menu-item menu-item-sitemap">

    <a href="/sitemap.xml" rel="section"><i class="fa fa-fw fa-sitemap"></i>Sitemap</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>Search
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container"></div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="algolia-results">
  <div id="algolia-stats"></div>
  <div id="algolia-hits"></div>
  <div id="algolia-pagination" class="algolia-pagination"></div>
</div>

      
    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-cn">
    <link itemprop="mainEntityOfPage" href="https://reku1997.gitee.io/2017/09/28/%E5%90%8E%E7%BC%80%E8%87%AA%E5%8A%A8%E6%9C%BA/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="Reku">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Reku">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          后缀自动机
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>

              <time title="Created: 2017-09-28 22:27:51" itemprop="dateCreated datePublished" datetime="2017-09-28T22:27:51+08:00">2017-09-28</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">Edited on</span>
                <time title="Modified: 2021-12-16 20:15:01" itemprop="dateModified" datetime="2021-12-16T20:15:01+08:00">2021-12-16</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/acm/" itemprop="url" rel="index"><span itemprop="name">acm</span></a>
                </span>
            </span>

          
            <span id="/2017/09/28/%E5%90%8E%E7%BC%80%E8%87%AA%E5%8A%A8%E6%9C%BA/" class="post-meta-item leancloud_visitors" data-flag-title="后缀自动机" title="Views">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">Views: </span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine: </span>
    
    <a title="valine" href="/2017/09/28/%E5%90%8E%E7%BC%80%E8%87%AA%E5%8A%A8%E6%9C%BA/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2017/09/28/%E5%90%8E%E7%BC%80%E8%87%AA%E5%8A%A8%E6%9C%BA/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>我们都知道后缀自动机的构造是比较难以理解的，所以我想先知道后缀自动机构建出来的东西是什么。 <span id="more"></span> 首先后缀自动机构造出来的一定是一个自动机，这个自动机可以接收一个字符串所有的后缀，显然这个自动机是一个DAG图。 然后这个自动机的每个状态代表什么呢？代表结束位置相同的子串，比如ab和aab在aabaab中都在<span class="math inline">\(3,6\)</span>位置结尾，那么这两个串可以认为在后缀自动机中是同一个状态。 后缀自动机大概维护这么几个东西：</p>
<p><span class="math inline">\(MAXLEN[ST]\)</span> : <span class="math inline">\(ST\)</span>对应的最长的字符串</p>
<p><span class="math inline">\(MINLEN[ST]\)</span> : <span class="math inline">\(ST\)</span>对应的最短的字符串</p>
<p><span class="math inline">\(TRANS[ST][]\)</span> : <span class="math inline">\(ST\)</span>对应的转移函数</p>
<p><span class="math inline">\(SLINK[ST]\)</span> : <span class="math inline">\(ST\)</span>对应的最小的超集，比如<span class="math inline">\((3,6,9)\)</span>是<span class="math inline">\((3,6)\)</span>的超集。</p>
<p><span class="math inline">\(SLINK\)</span>指向的状态一定是当前状态的一个前缀，而且形成的一定是一棵树</p>
<p><span class="math inline">\(ENDPOS[ST]\)</span> : <span class="math inline">\(ST\)</span>状态包含的子串的结束位置个数，可以通过<span class="math inline">\(SLINK\)</span>树自底向上来求出</p>
<p>至于这个后缀自动机的构造方法，就抄个板子？</p>
<p><a target="_blank" rel="noopener" href="http://hihocoder.com/problemset/problem/1445">http://hihocoder.com/problemset/problem/1445</a></p>
<blockquote>
<p>小Hi平时的一大兴趣爱好就是演奏钢琴。我们知道一个音乐旋律被表示为一段数构成的数列。 现在小Hi想知道一部作品中出现了多少不同的旋律？</p>
</blockquote>
<p>这个不同旋律出现的次数，对于每个状态，不同的子串个数为<span class="math inline">\(maxlen-minlen+1\)</span>，然后对每个状态算一算就好了。</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string">&lt;bits/stdc++.h&gt;</span></span></span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> MAXL = <span class="number">1000000</span>;</span><br><span class="line"><span class="keyword">char</span> s[MAXL + <span class="number">10</span>];</span><br><span class="line"><span class="keyword">int</span> n = <span class="number">0</span>, len, st;</span><br><span class="line"><span class="keyword">int</span> maxlen[<span class="number">2</span> * MAXL + <span class="number">10</span>], minlen[<span class="number">2</span> * MAXL + <span class="number">10</span>], trans[<span class="number">2</span> * MAXL + <span class="number">10</span>][<span class="number">26</span>], slink[<span class="number">2</span> * MAXL + <span class="number">10</span>];</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">new_state</span><span class="params">(<span class="keyword">int</span> _maxlen, <span class="keyword">int</span> _minlen, <span class="keyword">int</span>* _trans, <span class="keyword">int</span> _slink)</span> </span>&#123;</span><br><span class="line">        maxlen[n] = _maxlen;</span><br><span class="line">        minlen[n] = _minlen;</span><br><span class="line">        <span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; <span class="number">26</span>; i++) &#123;</span><br><span class="line">                <span class="keyword">if</span>(_trans == <span class="literal">NULL</span>)</span><br><span class="line">                        trans[n][i] = <span class="number">-1</span>;</span><br><span class="line">                <span class="keyword">else</span></span><br><span class="line">                        trans[n][i] = _trans[i];</span><br><span class="line">        &#125;</span><br><span class="line">        slink[n] = _slink;</span><br><span class="line">        <span class="keyword">return</span> n++;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">add_char</span><span class="params">(<span class="keyword">char</span> ch, <span class="keyword">int</span> u)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">int</span> c = ch - <span class="string">&#x27;a&#x27;</span>;</span><br><span class="line">        <span class="keyword">int</span> z = <span class="built_in">new_state</span>(maxlen[u] + <span class="number">1</span>, <span class="number">-1</span>, <span class="literal">NULL</span>, <span class="number">-1</span>);</span><br><span class="line">        <span class="keyword">int</span> v = u;</span><br><span class="line">        <span class="keyword">while</span>(v != <span class="number">-1</span> &amp;&amp; trans[v][c] == <span class="number">-1</span>) &#123;</span><br><span class="line">                trans[v][c] = z;</span><br><span class="line">                v = slink[v];</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span>(v == <span class="number">-1</span>) &#123; <span class="comment">//最简单的情况，suffix-path(u-&gt;S)上都没有对应字符ch的转移</span></span><br><span class="line">                minlen[z] = <span class="number">1</span>;</span><br><span class="line">                slink[z] = <span class="number">0</span>;</span><br><span class="line">                <span class="keyword">return</span> z;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">int</span> x = trans[v][c];</span><br><span class="line">        <span class="keyword">if</span>(maxlen[v] + <span class="number">1</span> == maxlen[x]) &#123; <span class="comment">//较简单的情况，不用拆分x</span></span><br><span class="line">                minlen[z] = maxlen[x] + <span class="number">1</span>;</span><br><span class="line">                slink[z] = x;</span><br><span class="line">                <span class="keyword">return</span> z;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">int</span> y = <span class="built_in">new_state</span>(maxlen[v] + <span class="number">1</span>, <span class="number">-1</span>, trans[x], slink[x]); <span class="comment">//最复杂的情况，拆分x</span></span><br><span class="line">        slink[y] = slink[x];</span><br><span class="line">        minlen[x] = maxlen[y] + <span class="number">1</span>;</span><br><span class="line">        slink[x] = y;</span><br><span class="line">        minlen[z] = maxlen[y] + <span class="number">1</span>;</span><br><span class="line">        slink[z] = y;</span><br><span class="line">        <span class="keyword">int</span> w = v;</span><br><span class="line">        <span class="keyword">while</span>(w != <span class="number">-1</span> &amp;&amp; trans[w][c] == x) &#123;</span><br><span class="line">                trans[w][c] = y;</span><br><span class="line">                w = slink[w];</span><br><span class="line">        &#125;</span><br><span class="line">        minlen[y] = maxlen[slink[y]] + <span class="number">1</span>;</span><br><span class="line">        <span class="keyword">return</span> z;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	<span class="built_in">scanf</span>(<span class="string">&quot;%s&quot;</span>,s+<span class="number">1</span>);</span><br><span class="line">	len=<span class="built_in">strlen</span>(s+<span class="number">1</span>);</span><br><span class="line">	st=<span class="built_in">new_state</span>(<span class="number">0</span>,<span class="number">0</span>,<span class="literal">NULL</span>,<span class="number">-1</span>);</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;=len;i++)</span><br><span class="line">	&#123;</span><br><span class="line">		st=<span class="built_in">add_char</span>(s[i],st);</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">long</span> <span class="keyword">long</span> ans=<span class="number">0</span>;</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;n;i++)</span><br><span class="line">	&#123;</span><br><span class="line">		ans+=maxlen[i]-minlen[i]+<span class="number">1</span>;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;%lld\n&quot;</span>,ans);</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><a target="_blank" rel="noopener" href="http://hihocoder.com/problemset/problem/1449">http://hihocoder.com/problemset/problem/1449</a></p>
<blockquote>
<p>小Hi平时的一大兴趣爱好就是演奏钢琴。我们知道一个音乐旋律被表示为一段数构成的数列。 现在小Hi想知道一部作品中所有长度为K的旋律中出现次数最多的旋律的出现次数。但是K不是固定的，小Hi想知道对于所有的K的答案。</p>
</blockquote>
<p>通过<span class="math inline">\(slink\)</span>树，我们可以构建出每个状态的结束位置个数，这样的话就知道了每个<span class="math inline">\(maxlen\)</span>出现了多少次，因为最后的答案一定是按照长度单调递减的，所以就维护一个类似于前缀最大值就好了。</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string">&lt;bits/stdc++.h&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> N = <span class="number">1e6</span>;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> M = <span class="number">26</span>;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">state</span> &#123;</span></span><br><span class="line">  <span class="keyword">int</span> maxlen, minlen, slink;</span><br><span class="line">  <span class="keyword">int</span> trans[M];</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line">state st[N * <span class="number">2</span> + <span class="number">10</span>];</span><br><span class="line"><span class="keyword">int</span> degree[N * <span class="number">2</span> + <span class="number">10</span>];</span><br><span class="line"><span class="keyword">int</span> endpos[N * <span class="number">2</span> + <span class="number">10</span>];</span><br><span class="line"><span class="keyword">bool</span> prefix[N * <span class="number">2</span> + <span class="number">10</span>];</span><br><span class="line"></span><br><span class="line"><span class="keyword">char</span> s[N + <span class="number">10</span>];</span><br><span class="line"><span class="keyword">int</span> size, last;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">new_state</span><span class="params">(<span class="keyword">int</span> maxlen, <span class="keyword">int</span> minlen, <span class="keyword">int</span> slink, <span class="keyword">int</span> *trans)</span> </span>&#123;</span><br><span class="line">  prefix[size] = <span class="literal">false</span>;</span><br><span class="line">  degree[size] = <span class="number">0</span>;</span><br><span class="line">  endpos[size] = <span class="number">0</span>;</span><br><span class="line">  st[size].maxlen = maxlen;</span><br><span class="line">  st[size].minlen = minlen;</span><br><span class="line">  st[size].slink = slink;</span><br><span class="line">  <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; M; i++) &#123;</span><br><span class="line">    <span class="keyword">if</span> (trans == <span class="literal">NULL</span>)</span><br><span class="line">      st[size].trans[i] = <span class="number">-1</span>;</span><br><span class="line">    <span class="keyword">else</span></span><br><span class="line">      st[size].trans[i] = trans[i];</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">return</span> size++;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">add_char</span><span class="params">(<span class="keyword">char</span> ch, <span class="keyword">int</span> u)</span> </span>&#123;</span><br><span class="line">  <span class="keyword">int</span> c = ch - <span class="string">&#x27;a&#x27;</span>, v, x, y;</span><br><span class="line">  <span class="keyword">int</span> cur = <span class="built_in">new_state</span>(st[u].maxlen + <span class="number">1</span>, <span class="number">-1</span>, <span class="number">-1</span>, <span class="literal">NULL</span>);</span><br><span class="line">  prefix[cur] = <span class="literal">true</span>;</span><br><span class="line">  endpos[cur] = <span class="number">1</span>;</span><br><span class="line">  </span><br><span class="line">  <span class="keyword">for</span> (v = u; v != <span class="number">-1</span> &amp;&amp; st[v].trans[c] == <span class="number">-1</span>; v = st[v].slink) &#123;</span><br><span class="line">    st[v].trans[c] = cur;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">if</span> (v == <span class="number">-1</span>) &#123;</span><br><span class="line">    st[cur].minlen = <span class="number">1</span>;</span><br><span class="line">    st[cur].slink = <span class="number">0</span>;</span><br><span class="line">    degree[<span class="number">0</span>]++;</span><br><span class="line">    <span class="keyword">return</span> cur;</span><br><span class="line">  &#125;</span><br><span class="line">  x = st[v].trans[c];</span><br><span class="line">  <span class="keyword">if</span> (st[v].maxlen + <span class="number">1</span> == st[x].maxlen) &#123;</span><br><span class="line">    st[cur].minlen = st[x].maxlen + <span class="number">1</span>;</span><br><span class="line">    st[cur].slink = x;</span><br><span class="line">    degree[x]++;</span><br><span class="line">    <span class="keyword">return</span> cur;</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  y = <span class="built_in">new_state</span>(st[v].maxlen + <span class="number">1</span>, <span class="number">-1</span>, st[x].slink, st[x].trans);</span><br><span class="line">  <span class="keyword">for</span> (<span class="keyword">int</span> w = v; w != <span class="number">-1</span> &amp;&amp; st[w].trans[c] == x; w = st[w].slink)</span><br><span class="line">    st[w].trans[c] = y;</span><br><span class="line">  st[x].slink = st[cur].slink = y;</span><br><span class="line">  degree[y] += <span class="number">2</span>;</span><br><span class="line">  st[x].minlen = st[cur].minlen = st[y].maxlen + <span class="number">1</span>;</span><br><span class="line">  st[y].minlen = st[st[y].slink].maxlen + <span class="number">1</span>;</span><br><span class="line"></span><br><span class="line">  <span class="keyword">return</span> cur;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">topo</span><span class="params">()</span> </span>&#123;</span><br><span class="line">  queue&lt;<span class="keyword">int</span>&gt; q;</span><br><span class="line">  <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i &lt; size; i++) &#123;</span><br><span class="line">    <span class="keyword">if</span> (degree[i] == <span class="number">0</span>)</span><br><span class="line">      q.<span class="built_in">push</span>(i);</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">while</span> (!q.<span class="built_in">empty</span>())&#123;</span><br><span class="line">    <span class="keyword">int</span> x = q.<span class="built_in">front</span>(); q.<span class="built_in">pop</span>();</span><br><span class="line">    endpos[st[x].slink] += endpos[x];</span><br><span class="line">    <span class="keyword">if</span> (--degree[st[x].slink] == <span class="number">0</span>)</span><br><span class="line">      q.<span class="built_in">push</span>(st[x].slink);</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">init</span><span class="params">()</span> </span>&#123;</span><br><span class="line">  size = <span class="number">0</span>;</span><br><span class="line">  last = <span class="built_in">new_state</span>(<span class="number">0</span>, <span class="number">0</span>, <span class="number">-1</span>, <span class="literal">NULL</span>);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">int</span> ans[N + <span class="number">10</span>];</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	<span class="built_in">scanf</span>(<span class="string">&quot;%s&quot;</span>,s+<span class="number">1</span>);</span><br><span class="line">	<span class="keyword">int</span> len=<span class="built_in">strlen</span>(s+<span class="number">1</span>);</span><br><span class="line">	<span class="built_in">init</span>();</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;=len;i++)</span><br><span class="line">	&#123;</span><br><span class="line">		last=<span class="built_in">add_char</span>(s[i],last);</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="built_in">topo</span>();</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i&lt;size;i++)</span><br><span class="line">	&#123;</span><br><span class="line">		ans[st[i].maxlen]=<span class="built_in">max</span>(ans[st[i].maxlen],endpos[i]);</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i=len<span class="number">-1</span>;i&gt;=<span class="number">1</span>;i--)</span><br><span class="line">	&#123;</span><br><span class="line">		ans[i]=<span class="built_in">max</span>(ans[i],ans[i+<span class="number">1</span>]);</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;=len;i++)</span><br><span class="line">	&#123;</span><br><span class="line">		<span class="built_in">printf</span>(<span class="string">&quot;%d\n&quot;</span>,ans[i]);</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><a target="_blank" rel="noopener" href="http://hihocoder.com/problemset/problem/1457">http://hihocoder.com/problemset/problem/1457</a></p>
<blockquote>
<p>小Hi平时的一大兴趣爱好就是演奏钢琴。我们知道一段音乐旋律可以被表示为一段数构成的数列。 神奇的是小Hi发现了一部名字叫《十进制进行曲大全》的作品集，顾名思义，这部作品集里有许多作品，但是所有的作品有一个共同特征：只用了十个音符，所有的音符都表示成0-9的数字。 现在小Hi想知道这部作品中所有不同的旋律的“和”（也就是把串看成数字，在十进制下的求和，允许有前导0）。答案有可能很大，我们需要对（10^9 + 7)取摸。</p>
</blockquote>
<p>用像后缀数组处理多串的方法，把所有的串都串起来，然后在DAG跑个DP套DP就好了。</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string">&lt;bits/stdc++.h&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> N = <span class="number">2e6</span>;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> M = <span class="number">11</span>;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">long</span> <span class="keyword">long</span> mod = <span class="number">1e9</span>+<span class="number">7</span>;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">state</span> &#123;</span></span><br><span class="line">  <span class="keyword">int</span> maxlen, minlen, slink;</span><br><span class="line">  <span class="keyword">int</span> trans[M];</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line">state st[N * <span class="number">2</span> + <span class="number">10</span>];</span><br><span class="line"><span class="keyword">int</span> degree[N * <span class="number">2</span> + <span class="number">10</span>];</span><br><span class="line"><span class="keyword">int</span> endpos[N * <span class="number">2</span> + <span class="number">10</span>];</span><br><span class="line"><span class="keyword">bool</span> prefix[N * <span class="number">2</span> + <span class="number">10</span>];</span><br><span class="line"><span class="keyword">int</span> indegree[N * <span class="number">2</span> + <span class="number">10</span>];</span><br><span class="line"><span class="keyword">long</span> <span class="keyword">long</span> valad[N * <span class="number">2</span> + <span class="number">10</span>];</span><br><span class="line"><span class="keyword">long</span> <span class="keyword">long</span> ans[N * <span class="number">2</span> + <span class="number">10</span>];</span><br><span class="line"><span class="keyword">long</span> <span class="keyword">long</span> sum;</span><br><span class="line"><span class="keyword">char</span> s[N + <span class="number">10</span>];</span><br><span class="line"><span class="keyword">char</span> c[N + <span class="number">10</span>];</span><br><span class="line"><span class="keyword">int</span> size, last;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">new_state</span><span class="params">(<span class="keyword">int</span> maxlen, <span class="keyword">int</span> minlen, <span class="keyword">int</span> slink, <span class="keyword">int</span> *trans)</span> </span>&#123;</span><br><span class="line">  prefix[size] = <span class="literal">false</span>;</span><br><span class="line">  degree[size] = <span class="number">0</span>;</span><br><span class="line">  endpos[size] = <span class="number">0</span>;</span><br><span class="line">  st[size].maxlen = maxlen;</span><br><span class="line">  st[size].minlen = minlen;</span><br><span class="line">  st[size].slink = slink;</span><br><span class="line">  <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; M; i++) &#123;</span><br><span class="line">    <span class="keyword">if</span> (trans == <span class="literal">NULL</span>)</span><br><span class="line">      st[size].trans[i] = <span class="number">-1</span>;</span><br><span class="line">    <span class="keyword">else</span></span><br><span class="line">      st[size].trans[i] = trans[i];</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">return</span> size++;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">add_char</span><span class="params">(<span class="keyword">char</span> ch, <span class="keyword">int</span> u)</span> </span>&#123;</span><br><span class="line">  <span class="keyword">int</span> c = ch - <span class="string">&#x27;0&#x27;</span>, v, x, y;</span><br><span class="line">  <span class="keyword">int</span> cur = <span class="built_in">new_state</span>(st[u].maxlen + <span class="number">1</span>, <span class="number">-1</span>, <span class="number">-1</span>, <span class="literal">NULL</span>);</span><br><span class="line">  prefix[cur] = <span class="literal">true</span>;</span><br><span class="line">  endpos[cur] = <span class="number">1</span>;</span><br><span class="line">  </span><br><span class="line">  <span class="keyword">for</span> (v = u; v != <span class="number">-1</span> &amp;&amp; st[v].trans[c] == <span class="number">-1</span>; v = st[v].slink) &#123;</span><br><span class="line">    st[v].trans[c] = cur;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">if</span> (v == <span class="number">-1</span>) &#123;</span><br><span class="line">    st[cur].minlen = <span class="number">1</span>;</span><br><span class="line">    st[cur].slink = <span class="number">0</span>;</span><br><span class="line">    degree[<span class="number">0</span>]++;</span><br><span class="line">    <span class="keyword">return</span> cur;</span><br><span class="line">  &#125;</span><br><span class="line">  x = st[v].trans[c];</span><br><span class="line">  <span class="keyword">if</span> (st[v].maxlen + <span class="number">1</span> == st[x].maxlen) &#123;</span><br><span class="line">    st[cur].minlen = st[x].maxlen + <span class="number">1</span>;</span><br><span class="line">    st[cur].slink = x;</span><br><span class="line">    degree[x]++;</span><br><span class="line">    <span class="keyword">return</span> cur;</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  y = <span class="built_in">new_state</span>(st[v].maxlen + <span class="number">1</span>, <span class="number">-1</span>, st[x].slink, st[x].trans);</span><br><span class="line">  <span class="keyword">for</span> (<span class="keyword">int</span> w = v; w != <span class="number">-1</span> &amp;&amp; st[w].trans[c] == x; w = st[w].slink)</span><br><span class="line">    st[w].trans[c] = y;</span><br><span class="line">  st[x].slink = st[cur].slink = y;</span><br><span class="line">  degree[y] += <span class="number">2</span>;</span><br><span class="line">  st[x].minlen = st[cur].minlen = st[y].maxlen + <span class="number">1</span>;</span><br><span class="line">  st[y].minlen = st[st[y].slink].maxlen + <span class="number">1</span>;</span><br><span class="line"></span><br><span class="line">  <span class="keyword">return</span> cur;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">topo</span><span class="params">()</span> </span>&#123;</span><br><span class="line">  queue&lt;<span class="keyword">int</span>&gt; q;</span><br><span class="line">  <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i &lt; size; i++) &#123;</span><br><span class="line">    <span class="keyword">if</span> (degree[i] == <span class="number">0</span>)</span><br><span class="line">      q.<span class="built_in">push</span>(i);</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">while</span> (!q.<span class="built_in">empty</span>())&#123;</span><br><span class="line">    <span class="keyword">int</span> x = q.<span class="built_in">front</span>(); q.<span class="built_in">pop</span>();</span><br><span class="line">    endpos[st[x].slink] += endpos[x];</span><br><span class="line">    <span class="keyword">if</span> (--degree[st[x].slink] == <span class="number">0</span>)</span><br><span class="line">      q.<span class="built_in">push</span>(st[x].slink);</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">init</span><span class="params">()</span> </span>&#123;</span><br><span class="line">  size = <span class="number">0</span>;</span><br><span class="line">  last = <span class="built_in">new_state</span>(<span class="number">0</span>, <span class="number">0</span>, <span class="number">-1</span>, <span class="literal">NULL</span>);</span><br><span class="line">  valad[<span class="number">0</span>] = <span class="number">1</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">int</span> n;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	<span class="built_in">scanf</span>(<span class="string">&quot;%d&quot;</span>,&amp;n);</span><br><span class="line">	<span class="keyword">int</span> len=<span class="number">0</span>;</span><br><span class="line">	<span class="built_in">init</span>();</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;=n;i++)</span><br><span class="line">	&#123;</span><br><span class="line">		<span class="built_in">scanf</span>(<span class="string">&quot;%s&quot;</span>,c+<span class="number">1</span>);</span><br><span class="line">		<span class="keyword">int</span> ll=<span class="built_in">strlen</span>(c+<span class="number">1</span>);</span><br><span class="line">		<span class="keyword">if</span>(len!=<span class="number">0</span>)</span><br><span class="line">		&#123;</span><br><span class="line">			len++;</span><br><span class="line">			s[len]=<span class="string">&#x27;0&#x27;</span>+<span class="number">10</span>;</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">1</span>;j&lt;=ll;j++)</span><br><span class="line">		&#123;</span><br><span class="line">			len++;</span><br><span class="line">			s[len]=c[j];</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;=len;i++)</span><br><span class="line">	&#123;</span><br><span class="line">		last=<span class="built_in">add_char</span>(s[i],last);</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i&lt;size;i++)</span><br><span class="line">	&#123;</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">0</span>;j&lt;M;j++)</span><br><span class="line">		&#123;</span><br><span class="line">			<span class="keyword">if</span>(st[i].trans[j]!=<span class="number">-1</span>)</span><br><span class="line">			&#123;</span><br><span class="line">				indegree[st[i].trans[j]]++;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	queue&lt;<span class="keyword">int</span>&gt; q;</span><br><span class="line">	q.<span class="built_in">push</span>(<span class="number">0</span>);</span><br><span class="line">	<span class="keyword">while</span>(!q.<span class="built_in">empty</span>())</span><br><span class="line">	&#123;</span><br><span class="line">		<span class="keyword">int</span> t=q.<span class="built_in">front</span>();</span><br><span class="line">		sum=(ans[t]+sum)%mod;</span><br><span class="line">		q.<span class="built_in">pop</span>();</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i&lt;M;i++)</span><br><span class="line">		&#123;</span><br><span class="line">			<span class="keyword">int</span> v=st[t].trans[i];</span><br><span class="line">			<span class="keyword">if</span>(v==<span class="number">-1</span>) <span class="keyword">continue</span>;</span><br><span class="line">			<span class="keyword">if</span>(i!=<span class="number">10</span>)</span><br><span class="line">			&#123;</span><br><span class="line">				valad[v]=(valad[v]+valad[t])%mod;</span><br><span class="line">				ans[v]=(ans[v]+ans[t]*<span class="number">10</span>+i*valad[t])%mod;</span><br><span class="line">			&#125;</span><br><span class="line">			indegree[v]--;</span><br><span class="line">			<span class="keyword">if</span>(indegree[v]==<span class="number">0</span>)</span><br><span class="line">			&#123;</span><br><span class="line">				q.<span class="built_in">push</span>(v);</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;%lld\n&quot;</span>,sum);</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><a target="_blank" rel="noopener" href="http://hihocoder.com/problemset/problem/1465">http://hihocoder.com/problemset/problem/1465</a></p>
<blockquote>
<p>小Hi平时的一大兴趣爱好就是演奏钢琴。我们知道一段音乐旋律可以被表示为一段数构成的数列。 小Hi发现旋律可以循环，每次把一段旋律里面最前面一个音换到最后面就成为了原旋律的“循环相似旋律”，还可以对“循环相似旋律”进行相同的变换能继续得到原串的“循环相似旋律”。 小Hi对此产生了浓厚的兴趣，他有若干段旋律，和一部音乐作品。对于每一段旋律，他想知道有多少在音乐作品中的子串（重复便多次计）和该旋律是“循环相似旋律”。</p>
</blockquote>
<p>对于循环同构的一个处理方法就是把字符串翻倍，然后看看最长公共子串是不是大于<span class="math inline">\(N\)</span>，问题就是怎么求这个最长公共子串。 我们用类似kmp的方法处理，然后用endpos记一下数，就好了。</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string">&lt;bits/stdc++.h&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> N = <span class="number">1e6</span>;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> M = <span class="number">26</span>;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">long</span> <span class="keyword">long</span> mod = <span class="number">1e9</span>+<span class="number">7</span>;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">state</span> &#123;</span></span><br><span class="line">  <span class="keyword">int</span> maxlen, minlen, slink;</span><br><span class="line">  <span class="keyword">int</span> trans[M];</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line">state st[N * <span class="number">2</span> + <span class="number">10</span>];</span><br><span class="line"><span class="keyword">int</span> degree[N * <span class="number">2</span> + <span class="number">10</span>];</span><br><span class="line"><span class="keyword">int</span> endpos[N * <span class="number">2</span> + <span class="number">10</span>];</span><br><span class="line"><span class="keyword">bool</span> prefix[N * <span class="number">2</span> + <span class="number">10</span>];</span><br><span class="line"><span class="keyword">bool</span> vis[N * <span class="number">2</span> + <span class="number">10</span>];</span><br><span class="line"><span class="keyword">char</span> s[N + <span class="number">10</span>];</span><br><span class="line"><span class="keyword">char</span> t[N + <span class="number">10</span>];</span><br><span class="line"><span class="keyword">int</span> size, last;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">new_state</span><span class="params">(<span class="keyword">int</span> maxlen, <span class="keyword">int</span> minlen, <span class="keyword">int</span> slink, <span class="keyword">int</span> *trans)</span> </span>&#123;</span><br><span class="line">  prefix[size] = <span class="literal">false</span>;</span><br><span class="line">  degree[size] = <span class="number">0</span>;</span><br><span class="line">  endpos[size] = <span class="number">0</span>;</span><br><span class="line">  st[size].maxlen = maxlen;</span><br><span class="line">  st[size].minlen = minlen;</span><br><span class="line">  st[size].slink = slink;</span><br><span class="line">  <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; M; i++) &#123;</span><br><span class="line">    <span class="keyword">if</span> (trans == <span class="literal">NULL</span>)</span><br><span class="line">      st[size].trans[i] = <span class="number">-1</span>;</span><br><span class="line">    <span class="keyword">else</span></span><br><span class="line">      st[size].trans[i] = trans[i];</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">return</span> size++;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">add_char</span><span class="params">(<span class="keyword">char</span> ch, <span class="keyword">int</span> u)</span> </span>&#123;</span><br><span class="line">  <span class="keyword">int</span> c = ch - <span class="string">&#x27;a&#x27;</span>, v, x, y;</span><br><span class="line">  <span class="keyword">int</span> cur = <span class="built_in">new_state</span>(st[u].maxlen + <span class="number">1</span>, <span class="number">-1</span>, <span class="number">-1</span>, <span class="literal">NULL</span>);</span><br><span class="line">  prefix[cur] = <span class="literal">true</span>;</span><br><span class="line">  endpos[cur] = <span class="number">1</span>;</span><br><span class="line">  </span><br><span class="line">  <span class="keyword">for</span> (v = u; v != <span class="number">-1</span> &amp;&amp; st[v].trans[c] == <span class="number">-1</span>; v = st[v].slink) &#123;</span><br><span class="line">    st[v].trans[c] = cur;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">if</span> (v == <span class="number">-1</span>) &#123;</span><br><span class="line">    st[cur].minlen = <span class="number">1</span>;</span><br><span class="line">    st[cur].slink = <span class="number">0</span>;</span><br><span class="line">    degree[<span class="number">0</span>]++;</span><br><span class="line">    <span class="keyword">return</span> cur;</span><br><span class="line">  &#125;</span><br><span class="line">  x = st[v].trans[c];</span><br><span class="line">  <span class="keyword">if</span> (st[v].maxlen + <span class="number">1</span> == st[x].maxlen) &#123;</span><br><span class="line">    st[cur].minlen = st[x].maxlen + <span class="number">1</span>;</span><br><span class="line">    st[cur].slink = x;</span><br><span class="line">    degree[x]++;</span><br><span class="line">    <span class="keyword">return</span> cur;</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  y = <span class="built_in">new_state</span>(st[v].maxlen + <span class="number">1</span>, <span class="number">-1</span>, st[x].slink, st[x].trans);</span><br><span class="line">  <span class="keyword">for</span> (<span class="keyword">int</span> w = v; w != <span class="number">-1</span> &amp;&amp; st[w].trans[c] == x; w = st[w].slink)</span><br><span class="line">    st[w].trans[c] = y;</span><br><span class="line">  st[x].slink = st[cur].slink = y;</span><br><span class="line">  degree[y] += <span class="number">2</span>;</span><br><span class="line">  st[x].minlen = st[cur].minlen = st[y].maxlen + <span class="number">1</span>;</span><br><span class="line">  st[y].minlen = st[st[y].slink].maxlen + <span class="number">1</span>;</span><br><span class="line"></span><br><span class="line">  <span class="keyword">return</span> cur;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">topo</span><span class="params">()</span> </span>&#123;</span><br><span class="line">  queue&lt;<span class="keyword">int</span>&gt; q;</span><br><span class="line">  <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i &lt; size; i++) &#123;</span><br><span class="line">    <span class="keyword">if</span> (degree[i] == <span class="number">0</span>)</span><br><span class="line">      q.<span class="built_in">push</span>(i);</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">while</span> (!q.<span class="built_in">empty</span>())&#123;</span><br><span class="line">    <span class="keyword">int</span> x = q.<span class="built_in">front</span>(); q.<span class="built_in">pop</span>();</span><br><span class="line">    endpos[st[x].slink] += endpos[x];</span><br><span class="line">    <span class="keyword">if</span> (--degree[st[x].slink] == <span class="number">0</span>)</span><br><span class="line">      q.<span class="built_in">push</span>(st[x].slink);</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">init</span><span class="params">()</span> </span>&#123;</span><br><span class="line">  size = <span class="number">0</span>;</span><br><span class="line">  last = <span class="built_in">new_state</span>(<span class="number">0</span>, <span class="number">0</span>, <span class="number">-1</span>, <span class="literal">NULL</span>);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">ff</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	<span class="built_in">scanf</span>(<span class="string">&quot;%s&quot;</span>,t+<span class="number">1</span>);</span><br><span class="line">	<span class="keyword">int</span> len=<span class="built_in">strlen</span>(t+<span class="number">1</span>);</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i&lt;size;i++)</span><br><span class="line">	&#123;</span><br><span class="line">		vis[i]=<span class="number">0</span>;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;=len;i++)</span><br><span class="line">	&#123;</span><br><span class="line">		t[len+i]=t[i];</span><br><span class="line">	&#125;</span><br><span class="line">	len*=<span class="number">2</span>;</span><br><span class="line">	<span class="keyword">int</span> u,l;</span><br><span class="line">	u=l=<span class="number">0</span>;</span><br><span class="line">	<span class="keyword">int</span> ans=<span class="number">0</span>;</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;=len;i++)</span><br><span class="line">	&#123;</span><br><span class="line">		<span class="keyword">int</span> v=t[i]-<span class="string">&#x27;a&#x27;</span>;</span><br><span class="line">		<span class="keyword">while</span>(u!=<span class="number">0</span> &amp;&amp; st[u].trans[v]==<span class="number">-1</span>)</span><br><span class="line">		&#123;</span><br><span class="line">			u=st[u].slink;</span><br><span class="line">			l=st[u].maxlen;</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">if</span>(st[u].trans[v]!=<span class="number">-1</span>)</span><br><span class="line">		&#123;</span><br><span class="line">			u=st[u].trans[v];</span><br><span class="line">			l++;</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">else</span></span><br><span class="line">		&#123;</span><br><span class="line">			u=l=<span class="number">0</span>;</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">if</span>(l&gt;len/<span class="number">2</span>)</span><br><span class="line">		&#123;</span><br><span class="line">			<span class="keyword">while</span>(st[st[u].slink].maxlen&gt;=len/<span class="number">2</span>)</span><br><span class="line">			&#123;</span><br><span class="line">				u=st[u].slink;</span><br><span class="line">				l=st[u].maxlen;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">if</span>(l&gt;=len/<span class="number">2</span> &amp;&amp; vis[u]==<span class="number">0</span>)</span><br><span class="line">		&#123;</span><br><span class="line">			vis[u]=<span class="number">1</span>;</span><br><span class="line">			ans+=endpos[u];</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span> ans;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">int</span> n;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	<span class="built_in">scanf</span>(<span class="string">&quot;%s&quot;</span>,s+<span class="number">1</span>);</span><br><span class="line">	<span class="keyword">int</span> len = <span class="built_in">strlen</span>(s+<span class="number">1</span>);</span><br><span class="line">	<span class="built_in">init</span>();</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">1</span>; i &lt;= len; i++)</span><br><span class="line">	&#123;</span><br><span class="line">		last = <span class="built_in">add_char</span>(s[i],last);</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="built_in">topo</span>();</span><br><span class="line">	<span class="built_in">scanf</span>(<span class="string">&quot;%d&quot;</span>,&amp;n);</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">1</span>; i &lt;= n; i++)</span><br><span class="line">	&#123;</span><br><span class="line">		<span class="built_in">printf</span>(<span class="string">&quot;%d\n&quot;</span>,<span class="built_in">ff</span>());</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/%E5%90%8E%E7%BC%80%E8%87%AA%E5%8A%A8%E6%9C%BA/" rel="tag"># 后缀自动机</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2017/09/20/%E8%99%9A%E6%A0%91/" rel="prev" title="虚树">
      <i class="fa fa-chevron-left"></i> 虚树
    </a></div>
      <div class="post-nav-item">
    <a href="/2017/10/31/2017-acmicpc-xian-by-ruiker/" rel="next" title="2017 ACM/ICPC 西安赛区小结 by ruiker @ 广东老乡">
      2017 ACM/ICPC 西安赛区小结 by ruiker @ 广东老乡 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          Table of Contents
        </li>
        <li class="sidebar-nav-overview">
          Overview
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">Reku</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">78</span>
          <span class="site-state-item-name">posts</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
        <span class="site-state-item-count">8</span>
        <span class="site-state-item-name">categories</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">96</span>
        <span class="site-state-item-name">tags</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/wyc-ruiker" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;wyc-ruiker" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://www.zhihu.com/people/reku1997" title="ZhiHu → https:&#x2F;&#x2F;www.zhihu.com&#x2F;people&#x2F;reku1997" rel="noopener" target="_blank"><i class="fa fa-fw fa-quora"></i>ZhiHu</a>
      </span>
      <span class="links-of-author-item">
        <a href="http://codeforces.com/profile/reku" title="CodeForces → http:&#x2F;&#x2F;codeforces.com&#x2F;profile&#x2F;reku" rel="noopener" target="_blank"><i class="fa fa-fw fa-code"></i>CodeForces</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://www.linkedin.cn/injobs/in/reku" title="Linkedin → https:&#x2F;&#x2F;www.linkedin.cn&#x2F;injobs&#x2F;in&#x2F;reku" rel="noopener" target="_blank"><i class="fa fa-fw fa-linkedin"></i>Linkedin</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://gitee.com/reku1997" title="Gitee → https:&#x2F;&#x2F;gitee.com&#x2F;reku1997" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>Gitee</a>
      </span>
      <span class="links-of-author-item">
        <a href="/./atom.xml" title="RSS → .&#x2F;atom.xml"><i class="fa fa-fw fa-rss"></i>RSS</a>
      </span>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 2016 – 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Reku</span>
</div>
  <div class="powered-by">Powered by <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a>
  </div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="Total Visitors">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="Total Views">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="//cdn.jsdelivr.net/npm/algoliasearch@4/dist/algoliasearch-lite.umd.js"></script>
<script src="//cdn.jsdelivr.net/npm/instantsearch.js@4/dist/instantsearch.production.min.js"></script>
<script src="/js/algolia-search.js"></script>














  

  
      

<script>
  if (typeof MathJax === 'undefined') {
    window.MathJax = {
      loader: {
        source: {
          '[tex]/amsCd': '[tex]/amscd',
          '[tex]/AMScd': '[tex]/amscd'
        }
      },
      tex: {
        inlineMath: {'[+]': [['$', '$']]},
        tags: 'ams'
      },
      options: {
        renderActions: {
          findScript: [10, doc => {
            document.querySelectorAll('script[type^="math/tex"]').forEach(node => {
              const display = !!node.type.match(/; *mode=display/);
              const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display);
              const text = document.createTextNode('');
              node.parentNode.replaceChild(text, node);
              math.start = {node: text, delim: '', n: 0};
              math.end = {node: text, delim: '', n: 0};
              doc.math.push(math);
            });
          }, '', false],
          insertedScript: [200, () => {
            document.querySelectorAll('mjx-container').forEach(node => {
              let target = node.parentNode;
              if (target.nodeName.toLowerCase() === 'li') {
                target.parentNode.classList.add('has-jax');
              }
            });
          }, '', false]
        }
      }
    };
    (function () {
      var script = document.createElement('script');
      script.src = '//cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js';
      script.defer = true;
      document.head.appendChild(script);
    })();
  } else {
    MathJax.startup.document.state(0);
    MathJax.texReset();
    MathJax.typeset();
  }
</script>

    

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : false,
      appId      : 'MWLzM550UOu69h3dgvbbLSsF-gzGzoHsz',
      appKey     : 'gkKnwm9FK0cu3ysJbcggsCDz',
      placeholder: "Just go go",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : true,
      lang       : '' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

</body>
</html>
